package com.jason.glidetest;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.jason.glidetest.utils.ImageURL;

/**
 * @Author: Jason
 * @Date: 15/12/25
 * @Time: 14:35
 */

public class SingleActivity extends Activity {

    ImageView iv_nomor, iv_gif, iv_round;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single);
        iv_nomor = (ImageView) findViewById(R.id.iv_nomor);
        iv_gif = (ImageView) findViewById(R.id.iv_gif);
        iv_round = (ImageView) findViewById(R.id.iv_round);

        Glide.with(this).load(ImageURL.imageUrl[2]).crossFade().into(iv_nomor);
        Glide.with(this).load(ImageURL.gitUrl[2]).crossFade().into(iv_gif);
        // 加载成圆形图
        Glide.with(this).load(ImageURL.imageUrl[4]).asBitmap().centerCrop().into(new BitmapImageViewTarget(iv_round) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable =
                        RoundedBitmapDrawableFactory.create(SingleActivity.this.getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                iv_round.setImageDrawable(circularBitmapDrawable);
            }
        });


    }
}
